package dictcn.com.control;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import com.tencent.weibo.oauthv1.OAuthV1;

public class AccessQqTokenKeeper {//保存腾讯用户的认证Oauth类
	
	private static final String PREFERENCES_NAME_QQ = "qqOauth";

	public static void keepQqAccessToken(Context context, OAuthV1 oauth) {
		
		SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME_QQ, Context.MODE_PRIVATE);
		Editor editor = pref.edit();
		editor.putString("token", oauth.getOauthToken());
		editor.putString("secret", oauth.getOauthTokenSecret());
		editor.commit();
	}

	
	public static void clearQqToken(Context context){
	    SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME_QQ, Context.MODE_PRIVATE);
	    Editor editor = pref.edit();
	    editor.clear();
	    editor.commit();
	}

	public static OAuthV1 readQqAccessToken(Context context){
		OAuthV1 oauth=new OAuthV1();
		SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME_QQ, Context.MODE_PRIVATE);
		oauth.setOauthToken(pref.getString("token", "-1"));
		oauth.setOauthTokenSecret(pref.getString("secret", "-1"));
		return oauth;
	}
}
